home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 2 / LSD and 17bit Compendium Deluxe - Volume II.iso / a / prog / cprog / voronoi.lha / memory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-19  |  869 b   |  50 lines

  1. #
  2. #include "defs.h"
  3. #include <stdio.h>
  4.  
  5. freeinit(fl, size)
  6. struct    Freelist *fl;
  7. int    size;
  8. {
  9. fl -> head = (struct Freenode *) NULL;
  10. fl -> nodesize = size;
  11. }
  12.  
  13. char *getfree(fl)
  14. struct    Freelist *fl;
  15. {
  16. int i; struct Freenode *t;
  17. if(fl->head == (struct Freenode *) NULL)
  18. {    t =  (struct Freenode *) myalloc(sqrt_nsites * fl->nodesize);
  19.     for(i=0; i<sqrt_nsites; i+=1)     
  20.         makefree((struct Freenode *)((char *)t+i*fl->nodesize), fl);
  21. };
  22. t = fl -> head;
  23. fl -> head = (fl -> head) -> nextfree;
  24. return((char *)t);
  25. }
  26.  
  27.  
  28.  
  29. makefree(curr,fl)
  30. struct Freenode *curr;
  31. struct Freelist *fl;
  32. {
  33. curr -> nextfree = fl -> head;
  34. fl -> head = curr;
  35. }
  36.  
  37. int total_alloc;
  38. char *myalloc(n)
  39. unsigned n;
  40. {
  41. char *t;
  42. if ((t=malloc(n)) == (char *) 0)
  43. {    fprintf(stderr,"Insufficient memory processing site %d (%d bytes in use)\n",
  44.         siteidx, total_alloc);
  45.      exit();
  46. };
  47. total_alloc += n;
  48. return(t);
  49. }
  50.